package com.woniuxy.credit_loans.collection_zhang.service.Impl;

import com.woniuxy.credit_loans.audit_li.dto.BonaDtoLi;
import com.woniuxy.credit_loans.collection_zhang.service.BonaService;
import com.woniuxy.credit_loans.entity.Bona;
import com.woniuxy.credit_loans.mapper.BonaMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BonaServiceImpl implements BonaService {

    @Autowired
    private BonaMapper bonaMapper;

    @Override
    public int insertSelectiveByUserId(BonaDtoLi record) {
        Bona bona = bonaMapper.selectByuserIdentyid(record.getUserIdentyid());
        if (bona != null) {
            bona.setBonaGrade(record.getBonaGrade());
            return bonaMapper.updateByPrimaryKeySelective(bona);
        }else {
            record.setBonaLevel("一级");
//
            int i = bonaMapper.insertSelectiveByUserId(record);

            return i;
        }
    }

    @Override
    public Bona selectByuserIdentyid(String userIdentyid) {
        return bonaMapper.selectByuserIdentyid(userIdentyid);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        int i = bonaMapper.deleteByPrimaryKey(id);
        return 0;
    }

    @Override
    public List<Bona> selectAll(String input) {
        List<Bona> bonas = bonaMapper.selectAll(input);
        return bonas;
    }

    @Override
    public int insertSelective(Bona record) {
        int i = bonaMapper.insertSelective(record);
        return i;
    }

    @Override
    public Bona selectByPrimaryKey(Long id) {
         Bona bona = bonaMapper.selectByPrimaryKey(id);
        return bona;
    }

    @Override
    public int updateByPrimaryKeySelective(Bona record) {
        bonaMapper.updateByPrimaryKeySelective(record);
        return 0;
    }
}
